import { Component, _decorator } from 'cc';
const { ccclass } = _decorator;

@ccclass("DestroyHook")
export class DestroyHook extends Component {

    private hooks: Function[] = []

    addHook(hook: Function) {
        this.hooks.push(hook)
    }

    onDestroy() {
        for (let i = this.hooks.length - 1; i >= 0; --i) {
            this.hooks[i]();
        }
    }

}